"""
带请求头User-Agent,模拟浏览器，获取和浏览器一致的内容
"""
import requests

url = 'https://www.baidu.com'
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                  "Chrome/86.0.4240.183 Safari/537.36"}
response = requests.get(url, headers=headers)
print(response.content.decode())
print(response.request.headers)
print(response.headers)

# 请求携带的cookies
cookies_dict1 = requests.utils.dict_from_cookiejar(response.request._cookies)
print(response.request._cookies)
print(cookies_dict1)
# 响应携带的cookies
cookies_dict2 = requests.utils.dict_from_cookiejar(response.cookies)
print(response.cookies)
print(cookies_dict2)